package fr.istic.linkedcv.server;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class GroupesImpl {
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
	
	@Persistent
	private String name;
	
	@Persistent
	private List<Key> personnesSet;

	public GroupesImpl(){
		
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Key> getPersonnesSet() {
		return personnesSet;
	}

	public void setPersonnesSet(List<Key> personnesSet) {
		
		this.personnesSet = personnesSet;
	}
	
	public void addPersonne(PersonneImpl personne){
		if(this.personnesSet==null){
			this.personnesSet = new ArrayList<Key>();
		}
		Key personneKey = personne.getEncodedKey();
		if(personnesSet.indexOf(personneKey)==-1){
			personnesSet.add(personneKey);
			personne.addGroupe(this.getKey());
		}
	}
	
	public void removePersonne(PersonneImpl personne){
		
		personnesSet.remove(personne.getEncodedKey());
		personne.removeGroupe(this.getKey());
	}
	public void setKey(Key key) {
		this.key = key;
	}
	public Key getKey() {
		return key;
	}
	

}
